<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>系统后台 - {$Think.config.INTENDANT_NAME} - by HemaCMS</title>
    <link href="__INTENDANT__/css/admin_style.css" rel="stylesheet" />
    <script src="__COMMON__/jquery.js"></script>
    <script src="__COMMON__/jquery.cookie.js"></script>
    <script src="__COMMON__/jquery.validate.min.js"></script> <!--表单验证-->
    <script src="__COMMON__/layer/layer.js"></script>
    <script src="__INTENDANT__/js/iteny.intendant.js"></script> <!-- 公共easyui JS -->
    <!-- <link href="__INTENDANT__/css/icons.css" rel="stylesheet" /> -->
    <link href="__INTENDANT__/css/iteny.css" rel="stylesheet" />

</head>
<body class="J_scroll_fixed">
<div class="wrap J_check_wrap">
   	<div class="nav">
	    <ul class="cc">
	        <li><a href="{:U('Site/user')}">用户管理</a></li>
	        <li class="current"><a href="{:U('Site/addUser')}">添加帐号</a></li>
	    </ul>
	 </div>
   <div class="table_list">
     <form class="J_ajaxForm" action="{:U('Site/addUser')}" name="addUser" method="post" id="addUser">

     <div class="h_a">基本属性</div>
     <div class="table_full">
     <table width="100%" class="table_form contentWrap">
          <input type="hidden" name="addUser" value="addUser" />
          <tbody>
            <tr>
              <th width="80">账户名</th>
              <td><input type="test" name="username" class="input length_4" id="username"></td>
            </tr>
            <tr>
              <th>密码</th>
              <td><input type="password" name="password" class="input length_4" id="password" value=""></td>
            </tr>
            <tr>
              <th>确认密码</th>
              <td><input type="password" name="passworded" class="input length_4" id="passworded" value=""></td>
            </tr>
            <tr>
              <th>E-mail</th>
              <td><input type="text" name="email" value="" class="input length_4" id="email" size="30"></td>
            </tr>
            <tr>
              <th>昵称</th>
              <td><input type="text" name="nickname" value="" class="input length_4" id="nickname"></td>
            </tr>
            <tr>
            <th>备注</th>
            <td><textarea name="remark" rows="2" cols="20" id="remark" class="inputtext" style="height:100px;width:500px;"></textarea></td>
          </tr>
            <tr>
              <th>所属角色</th>
              <td>
                <select name="role_id[][uid]">
                  <volist name="role" id="vo">
                    <option value="{$vo.id}">{$vo.title}</option>
                  </volist>
                </select>
              </td>
            </tr>
            <tr>
            <th>状态</td>
            <td><select name="status">
                  <option value="1" selected>开启</option>
                  <option value="0">禁止</option>
            </select></td>
          </tr>
          </tbody>
        </table>
     </div>
     <div class="btn_wrap">
        <div class="btn_wrap_pd">
          <button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">添加</button>
        </div>
      </div>
      </form>
    </div>
</div>
<script type="text/javascript">
var userdizhi = "{:U('Site/user')}";
var checkUsername = "{:U('SiteCom/checkUsername')}";
var checkNickname = "{:U('SiteCom/checkNickname')}";
var checkEmail = "{:U('SiteCom/checkEmail')}";
$(function(){
  jQuery.validator.addMethod("username", function(value, element) {
  var tel = /^[a-zA-Z][\w]{4,16}$/;
  return this.optional(element) || (tel.test(value));
  }, "以字母开头,5-17 字母、数字、下划线'_'");
  jQuery.validator.addMethod("password", function(value, element) {
  var tel = /^[a-zA-Z][\w]{7,16}$/;
  return this.optional(element) || (tel.test(value));
  }, "以字母开头,8-17 字母、数字、下划线'_'");
  // jQuery.validator.addMethod("qq", function(value, element) {
  // var tel = /^[1-9]\d{4,9}$/;
  // return this.optional(element) || (tel.test(value));
  // }, "qq号码格式错误");
  // jQuery.validator.addMethod("tel", function(value, element) {
  // var length = value.length;
  // var mobile = /(13[0-9]|14[0-9]|15[0-9]|18[0-9]|17[0-9])[0-9]{8}$/;
  // return this.optional(element) || (length == 11 && mobile.test(value));
  // }, "手机号码格式错误");
  jQuery.validator.addMethod("chinaese", function(value, element) {
  var chinaese = /^[\u4e00-\u9fa5]+$/;
  return this.optional(element) || (chinaese.test(value));
  }, "只能输入中文");
  $('form[name=addUser]').validate({
    errorElement : 'span',
    validClass: "success",  //非常重要
    success : function (label) {
      label.addClass('success');
    },

        rules : {
                username : {
                    required : true,
                    username : true,
                    remote : {
                      url : checkUsername,
                      type : 'post',
                      dataType : 'json',
                      data : {
                       username : function(){
                         return $('#username').val();
                       }
                     }
                    }
                },
                nickname : {
                   required : true,
                   rangelength : [2,6],
                   chinaese : true,
                   remote : {
                     url : checkNickname,
                     type : 'post',
                     dataType : 'json',
                     data : {
                       nickname : function(){
                         return $('#nickname').val();
                       }
                     }
                   }
                },
                password : {
                   required : true,
                   password : true
                },
                passworded : {
                   required : true,
                   equalTo : "#password"
                },
                email : {
                   required : true,
                   email : true,
                   remote : {
                      url : checkEmail,
                      type : 'post',
                      dataType : 'json',
                      data : {
                        email : function(){
                          return $('#email').val();
                        }
                     }
                   }
                },
            },
        messages : {
                username : {
                    required : "请输入账户名",
                    remote : '账户名已存在'
                },

                nickname : {
                     required : '请填写您的真实姓名',
                     rangelength : '真实姓名在2-12个字之间',
                     remote : '昵称已存在'
                },
                password : {
                    required : "请输入密码"
                },
                passworded : {
                    required : '请确认密码',
                    equalTo : '两次密码不一致'
                },
                email : {
                    required : "请输入email",
                    email: "email格式错误",
                    remote : '邮箱已存在'
                },
            },
            submitHandler: function(form)
            {
              if($('.J_ajax_submit_btn').attr("disabledSubmit")){
              $('.J_ajax_submit_btn').text('请勿重复提交...').prop('disabled', true).addClass('disabled');
              return false;
          }
        $('.J_ajax_submit_btn').attr("disabledSubmit",true);
            var param = $('form[name=addUser]').serialize();
            $.ajax({
              url: $('form[name=addUser]').attr('action'),
              dataType:'json',
              type:'POST',
              data:param,
              success: function(data) {
                if (data=='-20') {
                  ITENY.alert('提示','添加用户成功',1,'5000');
                  setTimeout(function(){
                      window.location.href=userdizhi;
                  },3000);
              }else if(data=='-2')
              {
                ITENY.alert('提示',"账号以字母开头,5-17 字母、数字、下划线'_'",2,'5000');
                $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
                $('.J_ajax_submit_btn').attr("disabledSubmit",'');            }
                else if(data=='-3')
                {
                  ITENY.alert('提示','账户名被占用',2,'5000');
                  $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
                  $('.J_ajax_submit_btn').attr("disabledSubmit",'');
                }
                else if(data=='-4')
                {
                  ITENY.alert('提示','昵称必须是中文',2,'5000');
                  $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
                  $('.J_ajax_submit_btn').attr("disabledSubmit",'');
                }
                else if(data=='-5')
                {
                  ITENY.alert('提示','真实姓名被占用',2,'5000');
                  $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
                  $('.J_ajax_submit_btn').attr("disabledSubmit",'');
                }
                else if(data=='-6'){
                  ITENY.alert('提示',"密码以字母开头,8-17 字母、数字、下划线'_'",2,'5000');
                  $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
                  $('.J_ajax_submit_btn').attr("disabledSubmit",'');
                }
                else if(data=='-7'){
                  ITENY.alert('提示','验证确认密码是否和密码一致',2,'5000');
                  $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
                  $('.J_ajax_submit_btn').attr("disabledSubmit",'');
                }
                else if(data=='-9'){
                  ITENY.alert('提示','邮箱格式不正确',2,'5000');
                  $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
                  $('.J_ajax_submit_btn').attr("disabledSubmit",'');
                }
                else if(data=='-12'){
                  ITENY.alert('提示','邮箱被占用',2,'5000');
                  $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
                  $('.J_ajax_submit_btn').attr("disabledSubmit",'');
                }
                else {
                  ITENY.alert('提示','未知错误，请联系管理员！',2,'5000');
                  $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
                  $('.J_ajax_submit_btn').attr("disabledSubmit",'');
                }
              }
          });
        }
  });
});
</script>
</body>
</html>